  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>运营平台</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.5 -->
  <link rel="stylesheet" href="/customer_plat/public/bootstrap/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="/customer_plat/public/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="/customer_plat/public/css/ionicons.min.css">
 
  <!--date-->
   <link rel="stylesheet" href="/customer_plat/public/datepicker/bootstrap-datepicker.min.css">
  
  <!-- Theme style -->
  <link rel="stylesheet" href="/customer_plat/public/dist/css/AdminLTE.min.css">
  <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
  <link rel="stylesheet" href="/customer_plat/public/dist/css/skins/_all-skins.min.css">
  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  
  <!--plugins-->
  <link rel="stylesheet" href="/customer_plat/public/plugins/datatables/dataTables.bootstrap.css">
  <!--[if lt IE 9]>
  <script src="/customer_plat/public/javascripts/html5shiv.min.js"></script>
  <script src="/customer_plat/public/javascripts/respond.min.js"></script>
  <![endif]-->
<script src="/customer_plat/public/plugins/jQuery/jquery-1.12.0.min.js"></script>
<script src="/customer_plat/public/layer/layer.js"></script>
<!-- Bootstrap 3.3.5 -->
<script src="/customer_plat/public/bootstrap/js/bootstrap.min.js"></script>
<script src="/customer_plat/public/bootstrap/js/bootstrap3-validation.js"></script>
<!--cityselect  -->
<script src="/customer_plat/public/javascripts/city/jquery.cityselect.js"></script>
<!-- AdminLTE App -->
<script src="/customer_plat/public/dist/js/app.js"></script>
<script src="/customer_plat/public/plugins/json2.js"></script>
<!--plugins-->
<script src="/customer_plat/public/plugins/datatables/jquery.dataTables.js"></script>
<script src="/customer_plat/public/plugins/datatables/dataTables.bootstrap.min.js"></script>

<script src="/customer_plat/public/plugins/jQueryUI/jquery-ui.js"></script>
<link rel="stylesheet" href="/customer_plat/public/plugins/jQueryUI/jquery-ui.css">
<script src="/customer_plat/public/datepicker/bootstrap-datepicker.min.js"></script>
<script src="/customer_plat/public/datepicker/bootstrap-datepicker.zh-CN.min.js"></script>
<!-- SlimScroll -->
<script src="/customer_plat/public/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="/customer_plat/public/plugins/fastclick/fastclick.js"></script>
<script src="/customer_plat/public/select2/select2.min.js"></script>
<link rel="stylesheet" href="/customer_plat/public/select2/select2.min.css">
<section class="content-header">
	<h1>
		<small></small>
	</h1>
</section>
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<div class="box">
				<div class="box-header  with-border">
					<h3 class="box-title">供应商列表</h3>
				</div>

				<div class="row box-header">
					<div class="col-md-1"></div>
										<div class="col-md-3">
											<div class="input-group">
												<span class="input-group-addon"> <label>关键字</label>
												</span> <input class="form-control" type="text" id="name"
													name="name"  >
											</div>
										</div>
										
										<div>
											<button type="button" class="btn btn-primary pull-left"
												onclick="supplier_load()">查询</button>
										</div>
										<div class="col-md-1">
											<button type="button" class="btn btn-primary pull-left"
												onclick="jump_supplier_add()">添加供应商</button>
										</div>
				</div>

				<!--/.box-header -->
				<div class="box-body">
					<table id="supplier_table" class="table table-bordered table-hover">
						<thead>
						</thead>
						<tbody>
						</tbody>
						<tfoot>
							<tr>
								
							</tr>
						</tfoot>
					</table>
				</div>
				<!-- /.box-body -->
			</div>
		</div>
	</div>
</section>





<style type="text/css">
.selected {
	background-color: #abb9d3 !important;
}
</style>
<script>
	var supplierTable = null;
	$(function() {
		supplierTable = $('#supplier_table')
				.DataTable(
						{
							"columns" : [ {
								"title" : ' ',
								"data" : null
							},{
								"title" : "简称",
								"data" : "shortName"
							},{
								"title" : "名称",
								"data" : "longName"
							},{
								"title" : "英文名称",
								"data" : "englishName"
							},{
								"title" : "企业法人",
								"data" : "legalPerson"
							},{
								"title" : "企业代码",
								"data" : "enterpriseCode"
							},{
								"title" : "联系人",
								"data" : "contactor"
							},{
								"title" : "状态",
								"data" : "status"
							},{
								"title" : "操作",
								"data" : null
							}],
							"paging" : true,
							"lengthChange" : false,
							"searching" : false,
							"ordering" : false,
							"info" : true,
							"autoWidth" : false,
							"serverSide" : true,
							"processing" : true,
							"language" : {
								"emptyTable" : '没有数据',
								"paginate" : {
									"previous" : '上一页',
									"next" : '下一页'
								},
								"info" : "第 _START_条到 _END_ 条，共 _TOTAL_ 条",
								"sInfoEmpty" : "第 0 条到 0 条结果，共 0 项"
							},
							"ajax" : {
								"url" : "@{supplier.SupplierManageAction.supplierListDo}",
								"type" : "POST",
								"data" : function(d) {
									//添加额外的参数传给服务器
									d.extra_search = supplier_serverParams();
								}
							},
							"columnDefs" : [
									{
										"targets" : [ 0 ],
										"createdCell" : function(td, cellData,
												rowData, row, col) {
											$(td)
													.html(
															"<button type='button' class='btn btn-box-tool fa fa-plus'>");
										}	
									},
									{
										"targets" : [ 7 ],
										"render" : function(data, type, full) {
											if (data == 0) {
												return "新建";
											} else if (data == 1) {
												return "审核中";
											} else if (data == 2) {
												return "通过";
											} else if (data == 3) {
												return "不通过";
											} else if (data == 4) {
												return "取消";
											}
										}
									},
									{
										"targets" : [ 8 ],
										"createdCell" : function(td, cellData,
												rowData, row, col) {
											$(td)
											.html("<a href='javascript:void(0);' onclick='jump_supplier_update("
															+ '"'
															+ rowData.supplierId
															+ '"'
															+ ")'>修改</a>&nbsp;&nbsp;"
															+"<a href='javascript:void(0);' onclick='update_supplier_status("
															+ '"'
															+ rowData.supplierId
															+ '"'
															+ ",2)'>删除</a>&nbsp;&nbsp;"
															+"<a href='javascript:void(0);' onclick='jump_supplier_cutter("
															+ '"'
															+ rowData.supplierId
															+ '",'
															+ '"'
															+ rowData.shortName
															+ '"'

															+ ")'>供应商刀具</a>&nbsp;&nbsp;");
										 
										}
									}

							]

						});

		
	    $('#supplier_table tbody').on('click', 'button', function () {
	        var tr = $(this).closest('tr');
	        var row = supplierTable.row(tr);
	        if ( row.child.isShown() ) {
	            row.child.hide();
	            tr.removeClass('shown');
	            $(this).addClass('fa-plus');
	            $(this).removeClass('fa-minus');
	        }
	        else {
	            // Open this row
	            row.child( formatData_supplier(row.data())).show();
	            tr.addClass('shown');
	            $(this).addClass('fa-minus');
	            $(this).removeClass('fa-plus');
	        }
	    } );

		

	});

	//查询参数
	function supplier_serverParams() {
		var name=$("#name").val();
		var params = {
			"name":name
		};
		return params;
	}

	//表格请求
	function supplier_load() {
		supplierTable.ajax.reload();
	}

	function binding_no_supplier(supplierId) {
	
		if(confirm("确定取消吗?")){
		var p_data = {
			"supplier_id" : supplierId
		};
		$.ajax({
			type : 'PUT',
			url : '@{supplier.SupplierManageAction.customerNoBindingSupplier}',
			dataType : 'JSON',
			data : p_data,
			success : function(data, status) {
				supplier_load();
			},
			error : function(XHR, status, errorThrown) {

			}
		});
		}
	}

	
	//跳转到更新界面
	function jump_supplier_update(supplierId) {
		var url = "@{supplier.SupplierManageAction.updateSupplier}";
		location.href= url+"?supplierId="+supplierId
	}
	//跳转到更新界面
	function jump_supplier_add(supplierId) {
		var url = "@{supplier.SupplierManageAction.addSupplier}";
		location.href= url;
	}
	function jump_supplier_cutter(supplierId,supp_name) {
		var url = "@{supplier.SupplierManageAction.supplierCutterIndex}";
		location.href= url+"?supplierId="+supplierId+"&supp_name="+supp_name;
	}
	
	//更新状供应商状态
	function update_supplier_status(id, status) {
		var p_data = {
			"supplierId" : id,
			"status" : status
		};
		if(confirm("确认要删除吗 ?")){
		$.ajax({
			type : 'PUT',
			url : '@{supplier.SupplierManageAction.customerNoBindingSupplier}',
			dataType : 'JSON',
			data : p_data,
			success : function(data, status) {
				$('#supplierEditModal').modal('hide');
				supplierTable.ajax.reload();
			},
			error : function(XHR, status, errorThrown) {

			}
		});
		}

	}

	//格式化数据
	function formatData_supplier(data) {
		var table_str = "<table  class='table table-striped table-bordered table-hover dataTables-example dataTable'>";
		var td_mobile = "<td>手机号码：" + data.mobile + "</td>";
		var td_telephone = "<td>电话号码：" + data.telephone + "</td>";
		var td_fax = "<td>传真号码：" + data.fax + "</td>";
		var td_email = "<td>邮箱:" + data.email + "</td>";
		
		
		var tr_r1="<tr>"+td_mobile+td_telephone+td_fax+td_email+"</tr>";

		var td_province = "<td>省份："+data.province+" 城市："+data.city+" 区："+data.district+"</td>";
		var td_address = "<td>具体地址：" + data.address + "</td>";
		var td_website="<td>网址："+data.website+"</td>";
		var td_supplierId="<td>供应商编号:"+data.supplierId+"</td>";
		var tr_r2="<tr>"+td_province+td_address+td_website+td_supplierId+"</tr>";
	    

		var td_textarea="<td colspan='4'>备注："+data.memo+"</td>";
		console.log(td_textarea);
		var tr_r3="<tr>"+td_textarea+"</tr>";
		table_str=table_str+tr_r1+tr_r2+tr_r3+"</table>";
		return table_str;
	}
</script>

